// MachineBase.h : Header for all sub systems

#pragma once

#include <stdlib.h>

#include "../Question/QuestionBase.h"
#include "../Management/Management.h"
#include "..\Render\Render.h"

enum MACHINESTATE
{
	// GENERAL STATE
	MACHINESTATE_NONE							=	0,
	MACHINESTATE_START							=	1,
	MACHINESTATE_SUSPENDED					=	2,
	MACHINESTATE_PAUSED						=	3,
	MACHINESTATE_END								=	4,
	MACHINESTATE_ERROR							=	5,

	// QUIZ MACHINE STATE
	QUIZMACHINESTATE_WAITINGANSWER	=	11,
	QUIZMACHINESTATE_SHOWRESULT			=	12,


	// RACE MACHINE STATE
	RACEMACHINESTATE_WAITINGSTART		=	21,

};


class MachineBase
{
protected:
	MACHINESTATE m_MachineState;

public:
	// Handle to deal with input key 
	virtual void InputKeyHandler(int) = 0;

	// Return the machine is active or not
	virtual bool IsClosed() {return m_MachineState == MACHINESTATE_END;};

	// Make machine run
	virtual void Run() =	0;

	// Set up machine
	virtual void Init()	=	0;

	// Shut down machine
	virtual void Exit()	=	0;

};

class QuizMachine: public MachineBase
{
public:
	QuizMachine();
	~QuizMachine();

	virtual void InputKeyHandler(int);
	virtual void Init();
	virtual void Exit();
	virtual void Run();
	void SetRender(SceneRender*);

private:
	QuestionProvider *m_QuestionProvider;
	QuestionPool *m_QuestionPool;	
	SceneRender* m_SceneRender;

	int m_CorrectCount;
	int m_WrongCount;
	bool m_LastQuestionCorrect;

	void PrintQuestion();
	void DisplayResult();
	void NextQuestion();
	void CheckAnswer(QuestionOption);
	bool IsLastQuestion();
	
};

class RaceMachine : public MachineBase
{
public:
	RaceMachine();
	~RaceMachine();

	virtual void InputKeyHandler(int);
	virtual void Init();
	virtual void Exit();
	virtual void Run();
	void SetRender(SceneRender*);

private:
	SceneRender *m_SceneRender;

	void RenderStartLine();

};
